package com.xjgc.msi.exo.wsclient;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.UUIDGenerator;

import java.io.Serializable;

/**
 * WebService客户端 标准请求格式
 *
 * @author: 小逗号
 * @date: 2023-12-26
 * @description:
 * @since:
 */
@Slf4j
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WsClientStandardRequest implements Serializable {
    public WsClientStandardRequest(String taskName, String data) {
        this(UUIDGenerator.generate(), taskName, data, null);
    }

    public WsClientStandardRequest(String serialNo, String taskName, String data) {
        this(serialNo, taskName, data, null);
    }

    private String serialNo;
    private String taskName;
    private String data;
    private String extend;


    public String[] getParamValues(String params) {
        String[] defaultValues = new String[]{serialNo, taskName, data, extend};
        String[] split = params.split(SEPARATOR);
        if (split.length != 4) {
            return defaultValues;
        }
        String[] values = new String[4];
        for (int i = 0; i < split.length; i++) {
            String param = split[i];
            if (Param.SERIAL_NO.toString().equals(param)) {
                values[i] = serialNo;
            } else if (Param.TASK_NAME.toString().equals(param)) {
                values[i] = taskName;
            } else if (Param.DATA.toString().equals(param)) {
                values[i] = data;
            } else if (Param.EXTEND.toString().equals(param)) {
                values[i] = extend;
            } else {
                //throw new JeecgBootException("");
                log.warn("无效的参数列表配置:{}", param);
            }
        }
        return values;
    }


    /**
     * 分隔符
     */
    public final static String SEPARATOR = ",";
    /**
     * 默认参数列表
     */
    public final static String DEFAULT_PARAMS = Param.SERIAL_NO + SEPARATOR + Param.TASK_NAME + SEPARATOR + Param.DATA + SEPARATOR + Param.EXTEND;

    /**
     * ws请求参数枚举
     */
    public enum Param {
        /*SERIAL_NO=流水号,TASK_NAME=任务名,DATA=数据报文,EXTEND预留*/
        SERIAL_NO,
        TASK_NAME,
        DATA,
        EXTEND,
        ;


    }

}
